package com.expmanage.actions.login;

import java.util.Map;
import com.opensymphony.xwork2.ActionContext;

public class tloginaction {
	private String username = "";
	private String password = "";
	private String image = "";

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	@SuppressWarnings("rawtypes")
	public String execute() {
		String str = "failed";
		System.out.println("image:" + image);
		ActionContext context = ActionContext.getContext();
		Map session = context.getSession();
		String rand = (String) session.get("rand");
		System.out.println("rand:" + rand);
		if (image.equals(rand)) {
			System.out.println("success");
			tDataObject conn;
			try {
				conn = new tDataObject();

				if (conn.checkUser(this.username.trim(), this.password.trim())) {
					str = "success";
					ActionContext.getContext().getSession()
							.put("user", this.getUsername());
					ActionContext.getContext().getSession()
						.put("role","teacher");
				} else {
					str = "failed";
				}
			} catch (Exception e) {

				e.printStackTrace();
			}

			return str;
		} else
			return str;
	}

}